import 'dart:async';
export 'location_model.dart';
import 'package:flutter/services.dart';
import 'location_model.dart';

class LocationResult {
  LocationData locationData;
  int res;
  String errorDes;
}

class FlutterLocation {
  static const MethodChannel _channel = const MethodChannel('flutter_location');

  static Future<String> get platformVersion async {
    final String version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future<LocationResult> getLocation() async {
    Map dataMap = await _channel.invokeMethod('getLocation');
    LocationResult result = LocationResult();
    if (dataMap['error'] != null) {
      result.errorDes = dataMap['error'];
      result.res = -1;
    } else {
      LocationData locationData = LocationData.fromMap(dataMap);
      result.locationData = locationData;
      result.res = 0;
    }
    return result;
  }
}
